<?php
/**
 * Description of BaseController
 * 基础服务
 * @author xukx
 */
class BaseController extends Controller {
    function actionIndex(){
		$title = "区域设置";
		//$this->setPageTitle($title);
        $request = new CHttpRequest();
        
        $where ="";
        if($request->getIsPostRequest()){
            $name = $request->getPost('name');
            if(!empty($name)){
                $where = " and Name='$name'";
            }
        }
        
        $dataProvider = new CActiveDataProvider('Area',array(
            'criteria' => array(
                'condition' => '1'.$where,
                'order' => 'AreaID desc',
            ),
            'pagination' => array(
                'pageSize' => 20
            ),
        ));
        
		
		$this->render('index',array(
            'title' => $title,
            'dataProvider' => $dataProvider,
            'name' => $request->getPost('name'),
        ));
		//不使用layout
		//$this->renderPartial('index');
	}
    
    /**
     * 新增区域
     * @author xukx 
     */
    public function actionAddArea(){
        $title = "区域设置";
        $request = new CHttpRequest();
        
        if($request->getIsPostRequest()){
            $area = new Area();
            $area->Name = $request->getPost('name');
            $area->DisplayName = $request->getPost('display_name');
            $area->Summary = $request->getPost('desc');
            
            $area->save();
            $this->redirect("index");
        }
        $this->render('addArea',array(
            'title' => $title,
            'info' => array(),
        ));
    }
    
    /**
     * 编辑区域
     * @author xukx 
     */
    public function actionEditArea(){
        $title = "区域设置";
        $request = new CHttpRequest();
        $AreaId = $request->getParam('id');
        $area = Area::model()->findByPk($AreaId);
        
        if($request->getIsPostRequest()){
            $area->Name = $request->getPost('name');
            $area->DisplayName = $request->getPost('display_name');
            $area->Summary = $request->getPost('desc');
            
            $area->save();
            $this->redirect("index");
        }
        $this->render('addArea',array(
            'title' => $title,
            'info'  => $area->attributes,
        ));
    }
    
    /**
     * 删除区域
     * @author xukx 
     */
    public function actionDelArea(){
        $title = "区域设置";
        $request = new CHttpRequest();
        $AreaId = $request->getParam('id');
        $result = Area::model()->deleteByPk($AreaId);
        $this->redirect("index");
    }
    
    /**
     * POS机列表
     * @author xukx 
     */
    public function actionPosSetting(){
        $title = "POS机管理";
        $request = new CHttpRequest();
        
        $where ="";
        if($request->getIsPostRequest()){
            $name = $request->getPost('name');
            if(!empty($name)){
                $where = " and Name='$name'";
            }
        }
        
        $dataProvider = new CActiveDataProvider('Pos',array(
            'criteria' => array(
                'condition' => '1'.$where,
                'order' => 'PosID desc',
            ),
            'pagination' => array(
                'pageSize' => 20
            ),
        ));
        $this->render("posList",array(
            'title' => $title,
            'dataProvider' => $dataProvider,
            'name' => $request->getPost('name'),
        ));
    }
}

?>
